#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@NAME          : user_api_model.py
@TIME          : 2025/03/01 17:30:00
@AUTHOR        : chenlip
@VERSION       : 0.1.0
@DESCRIPTION   : 用户API相关请求和响应模型定义，使用装饰器方式
'''

from flask_restx import fields, Api

# 模型注册函数
def register_user_models(api: Api):
    """
    将所有API模型注册到API对象
    
    Args:
        api: Flask-RestX API实例
    """
    # 通过装饰器方式定义和注册模型
    @api.model('BaseResponse')
    class BaseResponseModel:
        success = fields.Boolean(description='是否成功')
        message = fields.String(description='消息')
    
    @api.model('TokenResponse')
    class TokenResponseModel:
        success = fields.Boolean(description='是否成功')
        access_token = fields.String(description='访问令牌')
        token_type = fields.String(description='令牌类型')
    
    @api.model('UserExtension')
    class UserExtensionModel:
        current_points = fields.Integer(description='当前积分')
        current_level = fields.Integer(description='当前等级')
        last_login_time = fields.DateTime(description='最后登录时间')
        total_online = fields.Integer(description='累计在线时长（秒）')
        privacy_settings = fields.Raw(description='隐私设置')
    
    @api.model('UserLevel')
    class UserLevelModel:
        level_id = fields.Integer(description='等级ID')
        level_name = fields.String(description='等级名称')
        badge_icon = fields.String(description='等级徽章图标路径')
    
    # 定义依赖其他模型的复杂模型
    @api.model('UserInfo')
    class UserInfoModel:
        user_id = fields.Integer(description='用户ID')
        nickname = fields.String(description='昵称')
        loginname = fields.String(description='登录名')
        email = fields.String(description='邮箱')
        phone = fields.String(description='手机号')
        qq = fields.String(description='QQ号')
        avatar = fields.String(description='头像URL')
        description = fields.String(description='用户简介')
        status = fields.Integer(description='状态')
        role = fields.Integer(description='角色')
        is_ai_user = fields.Integer(description='是否AI用户')
        create_time = fields.DateTime(description='创建时间')
        update_time = fields.DateTime(description='更新时间')
        extension = fields.Nested(api.models['UserExtension'], description='用户扩展信息')
        level = fields.Nested(api.models['UserLevel'], description='用户等级信息')
        meta = fields.Raw(description='用户元数据')
    
    @api.model('LoginRequest')
    class LoginRequestModel:
        login_id = fields.String(required=True, description='用户名、邮箱或手机号')
        password = fields.String(required=True, description='密码')
        remember_me = fields.Boolean(description='是否记住登录状态', default=False)
    
    @api.model('LoginResponse')
    class LoginResponseModel:
        success = fields.Boolean(description='是否成功')
        message = fields.String(description='消息')
        data = fields.Nested(api.models['UserInfo'], description='用户信息')
        access_token = fields.String(description='访问令牌')
        refresh_token = fields.String(description='刷新令牌')
        token_type = fields.String(description='令牌类型')
    
    @api.model('RefreshTokenRequest')
    class RefreshTokenRequestModel:
        refresh_token = fields.String(required=True, description='刷新令牌')
    
    @api.model('ProfileResponse')
    class ProfileResponseModel:
        success = fields.Boolean(description='是否成功')
        message = fields.String(description='消息')
        data = fields.Nested(api.models['UserInfo'], description='用户信息')
    
    # 返回所有模型的字典，方便在API路由中使用
    return api.models
